<?php
namespace app\index\controller;
use think\Controller;
use think\Db;
use think\Session;
use app\common\controller\Api;
use app\common\model\Area;
use app\common\model\Version;
use fast\Random;
use think\Config;
class Recruitment extends Controller{
    /****
     Class register 		商家认证
     *@$post['front']		身份证正面
     *@$post['contrary']	身份证反面
     *@$post['handheld']	手持身份证
     *@$post['charter']		营业执照
     *@$post['coba']		门头照
    */
    public function recruitment(){
       $post = input('post.');   
       $pool='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
	   $word_length=11;
  	   $code = '';
       for ($i = 0, $mt_rand_max = strlen($pool) - 1; $i < $word_length; $i++){
       		$code .= $pool[mt_rand(0, $mt_rand_max)];
       }
        $data = [
        	'userid'						    =>$post['user_id'],
        	'business_corporation_image1'	   	=>$post['front'],
        	'business_corporation_image2'	   	=>$post['contrary'],
        	'business_corporation_image3'	   	=>$post['handheld'],
        	'business_license'				    =>$post['charter'],
        	'door_photo_image'				    =>$post['coba'],
        	'business_phone'				    =>$post['business_phone'],
        	'business_corporation'			    =>$post['business_corporation'],
        	'schoolid'						    =>$post['schoolid'],
        	'trade_model'					    =>$post['trade_model'],
        	'apply_reply'					    =>$post['apply_reply'],
        	'business_name'					    =>$post['business_name'],
        	'username'						    =>$code,
        	'status'						    =>'normal',
			'address'							=>$post['address']	,	
        	'apply_status'					    =>0,
        	'createtime'					    =>time()
        ];
        $manystore=Db::name('manystore')->insert($data);
        if($manystore){
       		$arr = [
		       'state'     => 1,
		       'message'   => "请求成功！"
	       	];
       }else{
       		$arr = [
		       'state'     => 0,
		       'message'   => "请求错误！"
	       	];
       }
       return json($arr); 
    }

    public function school(){
    	$school = Db::name('school')->where(['status'=>1])->field('id,agent_school_name,location,longitude,latitude')->select();
    	if($school){
       		$arr = [
		       'state'     => 1,
		       'school'	   =>$school,
		       'message'   => "请求成功！"
	       	];
       }else{
       		$arr = [
		       'state'     => 0,
		       'message'   => "请求错误！"
	       	];
       }
       return json($arr); 
    }

    public function uploading(){
        return action('index/common/upload');
    }
	public function condition(){
        $user_id = input('user_id');
		$manystore = Db::name('manystore')->where(['userid'=>$user_id])->find();
		if($manystore){
			$arr = [
		       'state'       => 1,
			   'manystore'   =>$manystore,
	       	];
		}else{
			$arr = [
		       'state'     	 => 1,
			   'manystore'   =>'',
	       	];
		}
		return json($arr); 
    }
	/**商家重新认证**/  
	public function again(){
		$user_id = input('user_id');
		$manystore = Db::name('manystore')->where(['userid'=>$user_id])->find();
		if($manystore){
			$manystore_delete = Db::name('manystore')->where(['userid'=>$user_id])->delete();
			if($manystore_delete){
				$arr = [
					'state'       => 1,
				];
			}else{
				$arr = [
					'state'       => 0,
				];
			}
			
		}
	}
   


}